package com.bjpowernode.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.bjpowernode.entity.TActivity;
import com.bjpowernode.entity.vo.NameValueDataVO;
import com.bjpowernode.entity.vo.SummaryDataVO;
import com.bjpowernode.mapper.TActivityMapper;
import com.bjpowernode.mapper.TClueMapper;
import com.bjpowernode.mapper.TCustomerMapper;
import com.bjpowernode.mapper.TTranMapper;
import com.bjpowernode.service.StatisticService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@RequiredArgsConstructor
@Slf4j
public class StatisticServiceImpl implements StatisticService {

    private final TActivityMapper activityMapper;

    private final TClueMapper clueMapper;

    private final TCustomerMapper customerMapper;

    private final TTranMapper tranMapper;


    @Override
    public SummaryDataVO summaryData() {
        SummaryDataVO summaryDataVO = new SummaryDataVO();
        SummaryDataVO tempVO = new SummaryDataVO();
        //获取线索总数
        tempVO = clueMapper.getSummaryData();
        summaryDataVO.setTotalClueCount(tempVO.getTotalClueCount());
        //获取客户总数
        tempVO = customerMapper.getSummaryData();
        summaryDataVO.setTotalCustomerCount(tempVO.getTotalCustomerCount());
        //交易总额，已成单/未成单
        tempVO = tranMapper.getSummaryData();
        summaryDataVO.setTotalTranAmount(tempVO.getTotalTranAmount());
        summaryDataVO.setSuccessTranAmount(tempVO.getSuccessTranAmount());
        //获取市场活动在运行/不在运行
        tempVO = activityMapper.getSummaryData();
        summaryDataVO.setTotalActivityCount(tempVO.getTotalActivityCount());
        summaryDataVO.setGoingActivityCount(tempVO.getGoingActivityCount());

        return summaryDataVO;
    }

    @Override
    public List<NameValueDataVO> getSaleFunnel() {
        List<NameValueDataVO> resultList = new ArrayList<>();
        resultList.add(new NameValueDataVO("线索", clueMapper.getClueCount()));
        resultList.add(new NameValueDataVO("客户", customerMapper.getCustomerCount()));
        resultList.add(new NameValueDataVO("交易",tranMapper.getTranCountByStage(null)));
        resultList.add(new NameValueDataVO("成交",tranMapper.getTranCountByStage(42)));
        return resultList;
    }

    @Override
    public List<NameValueDataVO> getCluePieData() {
        List<NameValueDataVO> list = clueMapper.selectClueSourceCount();
        return list;
    }
}
